import { RequestConfig } from 'umi';
import type { RequestOptionsInit } from 'umi-request';

/**
 * 异常处理程序
 * @see https://beta-pro.ant.design/docs/request-cn
 */
const authHeaderInterceptor = (url: string, options: RequestOptionsInit) => {
  return {
    url,
    options: {
      ...options,
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json;charset=UTF-8',
      },
    },
  };
};

export const request: RequestConfig = {
  timeout: 1000,
  errorConfig: {},
  prefix: WEB_DOMAIN.apiDomain,
  requestInterceptors: [authHeaderInterceptor],
};
